home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / music / 87 / c / clines.c < prev    next >
C/C++ Source or Header  |  1986-12-19  |  32KB  |  813 lines

  1. /********************************************************************/
  2. /*                             C_LINES.C                            */
  3. /********************************************************************/
  4. /*             1986 by David Archibald. CIS 73256,2640              */
  5. /*          Released to the public domain on Dec. 6, 1986.          */
  6. /*                                                                  */
  7. /*     This program is compatible with both Alcyon and Megamax.     */
  8. /*------------------------------------------------------------------*/
  9. /* This program adds line numbers to a C text file, and then sends  */
  10. /* the file to the screen, printer or a disk file.                  */
  11. /*                                                                  */
  12. /*------------------------------------------------------------------*/
  13. /* The command line reads:                                          */
  14. /*         A:inputFile [B:outputFile] [-a] [-s] [-p] [-h] [-f {xx}] */
  15. /*         [-t {x}] [-c] [-b {xxxxx}]                               */
  16. /*------------------------------------------------------------------*/
  17. /* All of the commands, and any numbers that follow them, must be   */
  18. /* separated on the command line by a space. All the commands that  */
  19. /* are inclosed by brackets, are optional.                          */
  20. /*------------------------------------------------------------------*/
  21. /* inputFile - is the C text file name. It must be the 1st command  */
  22. /*             on the command line.                                 */
  23. /*                                                                  */
  24. /* outputFile - is the file name that the output from the -a and -s */
  25. /*              is sent to. A file name is required with either of  */
  26. /*              these commands, and it must be the 1st item         */
  27. /*              following the inputFile name, on the command line.  */
  28. /*__________________________________________________________________*/
  29. /* the use of a RAM disk with these two commands, is  *highly*      */
  30. /* recommended.                                                     */
  31. /*------------------------------------------------------------------*/
  32. /* -a        - adds line numbers to each line, and then save it to  */
  33. /*             the outputFile.                                      */
  34. /*                                                                  */
  35. /* -s        - strips the line numbers from a inputFile that was    */
  36. /*             previously created, by using the '-a' command.       */
  37. /*------------------------------------------------------------------*/
  38. /* All of the following commands are ignored, when the -a or -s     */
  39. /* commands are chosen.                                             */
  40. /*------------------------------------------------------------------*/
  41. /* These two commands work with both screen or printer output.      */
  42. /*------------------------------------------------------------------*/
  43. /*                                                                  */
  44. /* -c        - truncates the output line whenever it's length       */
  45. /*             exceeds 80 characters (counting the line number).    */
  46. /*             This command works with both screen or printer output*/
  47. /*                                                                  */
  48. /* -b        - skips 'x' amount of inputFile's lines. Does not print*/
  49. /*             any lines, until the line number that follows -b on  */
  50. /*             the command is reached. This command does not have   */
  51. /*             default line number. If no line number is entered,   */
  52. /*             then the program will begin printing at line 1.      */
  53. /*------------------------------------------------------------------*/
  54. /*                                                                  */
  55. /* -p        - sends the text file to the printer. If a wrap-around */
  56. /*             occurs, the text on the 2nd line is indented, so     */
  57. /*             that it starts on the same column as the 1st line    */
  58. /*             (it takes into account the line number).             */
  59. /*                                                                  */
  60. /*------------------------------------------------------------------*/
  61. /*  the following commands are ignored, unless the output is sent   */
  62. /*  to the printer.                                                 */
  63. /*------------------------------------------------------------------*/
  64. /*                                                                  */
  65. /* -h        - sends a header to the printer. The header consists   */
  66. /*             of 6 lines. The 1st two are blank, the 3rd is the    */
  67. /*             name of the file being listed, the 4th is the page   */
  68. /*             number and the time (24 hour clock) & date of        */
  69. /*             printing, and the 5th and 6th are blank.             */
  70. /*                                                                  */
  71. /* -f        - prints 'x' amount of blank lines at the bottom of the*/
  72. /*             page to skip over the perf. The the number of blank  */
  73. /*             lines is entered on the command line, after the -f   */
  74. /*             command. The maximum number is 6 lines. If there is  */
  75. /*             no number, then the footer defaults to 3 lines.      */
  76. /*                                                                  */
  77. /* -t        - Tabs the printout over a user defined amount of      */
  78. /*             up to 15 spaces. If no number follows the -t command,*/
  79. /*             then the tab defaults to 6 spaces.                   */
  80. /*                                                                  */
  81. /*------------------------------------------------------------------*/
  82. /* If you enter only a input file name, the defaults are:           */
  83. /*                                                                  */
  84. /* output to the screen, no header, no tab, no truncate, no footer, */
  85. /* and start output at line number 1.                               */
  86. /*------------------------------------------------------------------*/
  87. /* These commands work whether the file is going to the, disk       */
  88. /* printer or screen:                                               */
  89. /*               pressing 'Q' exits the program.                    */
  90. /*               pressing 'p' pauses the program, and               */
  91. /*                any other key restarts it.                        */
  92. /*                                                                  */
  93. /********************************************************************/
  94. /*              I M P O R T A N T   N O T E ! ! ! !                 */
  95. /*                                                                  */
  96. /* If you are going to compile this program with Alcyon, you must   */
  97. /* enlarge the STACK size in the "Gemstart" link file, otherwise    */
  98. /* the stack will overflow and start to overwrite the programs      */
  99. /* variables (I changed the stack size from 1K to 3K). If you are   */
  100. /* using Megamax, just ignore this.                                 */
  101. /********************************************************************/
  102.  
  103.  
  104. #include <stdio.h>
  105. #include <osbind.h>
  106. #include <string.h>
  107.  
  108. #define EMPTY 0
  109. #define CONT 1
  110. #define QUIT 0
  111. #define ON 1
  112. #define TOLOWER(c) ((c)>='A' && (c)<='Z' ? (c)+=32:(c)) 
  113.            /* Alcyon doesn't have this and we need it with Megamax. */
  114.  
  115. typedef int VOID;           /* needed only with Megamax */
  116.  
  117. struct cm {
  118.           int strip;
  119.           int add;
  120.           int print;
  121.           int header;
  122.           int footer;
  123.           int foot_amt;
  124.           int tab;
  125.           int tab_amt;
  126.           int line_num;
  127.           int prt_cnt;
  128.           int page_no;
  129.           int trun;
  130.           int begin;
  131.           int start_ln;
  132.           };
  133.  
  134. /* ------------global variables: for input & output files------------ */
  135.  
  136. FILE *fp_in;
  137. FILE *fp_out;
  138. FILE *fopen();                /* needed only with Alcyon */
  139.  
  140. main (argc,argv)
  141. int argc;
  142. char *argv[];
  143.  
  144. {
  145. int flag=CONT, t, esc=0x011b;
  146. char str_in[255];
  147. static struct cm command={0};
  148.  
  149.  
  150.      Cconout(esc);                 /* turn cursor off (it looks better*/
  151.      Cconout('f');                 /* when outputing with it off.)    */
  152.  
  153.      Cconout(esc);                 /* clear the screen.               */
  154.      Cconout('E');
  155.  
  156.      parse_cmd(argv,&command,argc);           /* get commands entered */
  157.  
  158.      flag=open_input(argv,argc);                 /* open input C file */
  159.  
  160.      if ((command.add==ON || command.strip==ON) && flag==CONT)
  161.        flag=open_out(argv);                       /* open output file */
  162.  
  163.      while(flag==CONT)
  164.      {
  165.           flag=keypress();                      /* check for keypress */
  166.            if (flag==QUIT)  break;
  167.  
  168. /*____________________________________________________________________*/
  169. /*         read line from input file. flag=0 if EOF reached.          */
  170. /*--------------------------------------------------------------------*/
  171.           flag=get_str(str_in);
  172.  
  173. /*____________________________________________________________________*/
  174. /*    after the last line has been read, wait for keypress before     */
  175. /*           returning to the desktop or the command mode.            */
  176. /*--------------------------------------------------------------------*/
  177.      if (flag==QUIT)
  178.      {
  179.           pause();                 /* wait until key is pressed       */
  180.           break;
  181.      }
  182.  
  183. /*____________________________________________________________________*/
  184. /*  if you don't want to start at the 1st line in the file then loop  */
  185. /*       until the line number that was entered is reached.           */
  186. /*--------------------------------------------------------------------*/
  187.      if (command.begin==ON && command.line_num+1<command.start_ln)
  188.      {
  189.           skip_lines(&command);
  190.           continue;                          /* skip other commands.  */
  191.      }
  192.  
  193. /*____________________________________________________________________*/
  194. /*      strip line number off input line & write to output file       */
  195. /*--------------------------------------------------------------------*/
  196.      else if (command.strip==ON)
  197.           {
  198.           strip_num(str_in);
  199.           continue;                          /* skip other commands.  */ 
  200.           }
  201.  
  202. /*____________________________________________________________________*/
  203. /*           add line number to line & write to output file           */
  204. /*--------------------------------------------------------------------*/
  205.      else if (command.add==ON)
  206.           {
  207.           add_num(str_in, &command);
  208.           continue;                /* once again--don't check for cmd */
  209.           }
  210.  
  211. /*____________________________________________________________________*/
  212. /*                       send line to printer                         */
  213. /*--------------------------------------------------------------------*/
  214.      else if (command.print==ON)
  215.                flag=printer(str_in, &command, argv);
  216.  
  217. /*____________________________________________________________________*/
  218. /*                       or send line to screen                       */
  219. /*--------------------------------------------------------------------*/
  220.      else    flag=prt_crt(str_in, &command);
  221.      }
  222.  
  223.    Cconout(esc);                         /* turn cursor back on.      */
  224.    Cconout('e');
  225.  
  226.    if (fp_in!=0)  fclose(fp_in);
  227.    if (fp_out!=0)  fclose(fp_out);
  228.  
  229. }
  230.  
  231.  
  232. VOID parse_cmd(cmd_line, c, num)
  233. char *cmd_line[];
  234. struct cm *c;
  235. int num;
  236.  
  237. {
  238. int t, amt;
  239.  
  240.      for (t=2;t<num;++t)            /* loop 'til all commands checked */
  241.      {
  242.           if (cmd_line[t][0]!='-')       /* don't treat 2nd file name */
  243.             continue;                    /* as command, check for '-'.*/
  244.    
  245.           switch(TOLOWER(cmd_line[t][1]))  /* if the command is upper-*/ 
  246.         {                                  /* case then make it lower.*/
  247.                case 's':
  248.                     c->strip=ON;    /* strip line #'s from input file */
  249.                     return(EMPTY);       /* ignore all other commands */
  250.  
  251.                case 'a':
  252.                     c->add=ON;          /* add line #'s to input file */
  253.                     return(EMPTY);       /* ignore all other commands */
  254.  
  255.                case 'p':
  256.                     c->print=ON;        /* send output to the printer */
  257.                     break;                  /* check for next command */
  258.  
  259.                case 'c':
  260.                     c->trun=ON;         /* truncate output to screen  */
  261.                     break;              /* or prt past 80 characters. */
  262.  
  263.                case 'h':
  264.                     c->header=ON;          /* print header to printer */
  265.                     break;                  /* check for next command */
  266.  
  267.                case 'f':
  268.                     c->footer=ON;          /* print footer to printer */
  269.  
  270. /*____________________________________________________________________*/
  271. /*            check if the size of footer follows command             */
  272. /*--------------------------------------------------------------------*/
  273.           c->foot_amt=3;          /* incase no size entered = default */
  274.  
  275.           if (t+1<num)
  276.           {
  277.                amt=atoi(cmd_line[t+1]);   /* get number after '-f'    */
  278.                if (amt<0 || amt>6)        /* make it fall in range    */
  279.                     amt=6;
  280.  
  281.                if (amt!=0)
  282.                {
  283.                     c->foot_amt=amt;   /* if all ok, then equal input */
  284.                     ++t;                  /* move loop pointer past # */
  285.                }
  286.           }
  287.                     break;                /* check for next command.  */
  288.  
  289.  
  290.                case 'b':
  291.                     c->begin=ON;                     /* skip lines.   */
  292.  
  293. /*____________________________________________________________________*/
  294. /*              check for the line number to skip to                  */
  295. /*--------------------------------------------------------------------*/
  296.  
  297.           if (t+1<num)
  298.           {
  299.                amt=atoi(cmd_line[t+1]);   /* get number after '-b'    */
  300.                if (amt<0)                 /* make it fall in range    */
  301.                     amt=0;                /* <0 then don't skip any.  */
  302.  
  303.                if (amt!=0)
  304.                {
  305.                     c->start_ln=amt;   /* if all ok, then equal input */
  306.                     ++t;                  /* move loop pointer past # */
  307.                }
  308.           }
  309.                     break;                /* check for next command.  */
  310.  
  311.  
  312.                case 't':
  313.                     c->tab=ON;                      /* tab to printer */
  314.  
  315. /*____________________________________________________________________*/
  316. /*                check if size of tab follows command                */
  317. /*--------------------------------------------------------------------*/
  318.           c->tab_amt=6;           /* incase no size entered = default */
  319.  
  320.           if (t+1<num)
  321.           {
  322.                amt=atoi(cmd_line[t+1]);    /* get number after '-t'.  */
  323.                if (amt<0 || amt>15)        /* make it fall in range   */
  324.                     amt=15;
  325.  
  326.                if (amt!=0)
  327.                {
  328.                     c->tab_amt=amt;       /* if all ok, equal input   */
  329.                     ++t;                  /* move loop pointer past # */
  330.                }
  331.           }
  332.          }
  333.      }
  334. }
  335.  
  336.  
  337.  
  338. keypress()
  339.  
  340. {
  341. char ch;
  342.  
  343.      if (Cconis()<0)               /* is there a character available? */
  344.      {
  345.           ch=Cnecin();
  346.      if (ch=='p' || ch=='P')                        /* pause listing? */
  347.           ch=Cnecin();                           /* wait for keypress */
  348.      if (ch=='q' || ch=='Q')  return(QUIT);      /* quit the program  */
  349.      }
  350.      return(CONT);
  351. }
  352.  
  353.  
  354.  
  355. open_input(cmd_line,num)
  356.  
  357. int num;
  358. char *cmd_line[];
  359. {
  360.    if (num>2 && cmd_line[2][0]!='-')         /* are there 2 names for */
  361.                                                   /* strcmp to check. */
  362.      if (strcmp(cmd_line[1],cmd_line[2])==0)      /* check if input & */
  363.      {                                    /* output name are the same.*/
  364.           printf("\n\nWHOA! both the input and");
  365.           printf(" the output names are the same: %s\n",cmd_line[1]);
  366.           pause();
  367.           return(QUIT);                           /* exit the program.*/
  368.      }
  369.  
  370.      fp_in=fopen(cmd_line[1],"r");
  371.       if (fp_in==0)
  372.      {
  373.           printf("\nCannot open input file: %s \n",cmd_line[1]);
  374.           pause();
  375.           return(QUIT);         /* set flag to 0 on return & exit prg. */
  376.      }
  377.  
  378.      return(CONT);
  379. }
  380.  
  381.  
  382.  
  383. open_out(cmd_line)
  384.  
  385. char *cmd_line[];
  386. {
  387.      if (cmd_line[2][0]!='-')               /* don't use a command as */
  388.        fp_out=fopen(cmd_line[2],"w");         /* the 2nd file name.   */
  389.  
  390.      if (fp_out==0)
  391.      {
  392.           printf("\nCannot open output file: %s \n",cmd_line[2]);
  393.           pause();
  394.           return(QUIT);   /* set 'flag' to 0 on return & exit program */
  395.      }
  396.  
  397.      return(CONT);
  398. }
  399.  
  400.  
  401.  
  402. get_str(line)
  403.  
  404. char line[];
  405. {
  406.  
  407.      fgets(line,255,fp_in);              /* read line from input file */                      
  408.  
  409.      if (line[0]=='\0')
  410.           return(QUIT);                  /* when EOF then all done    */
  411.  
  412.      else return(CONT);
  413. }
  414.  
  415.  
  416. /*____________________________________________________________________*/
  417. /*               save input line back to output file minus            */
  418. /*                 the line number at the start of line.              */
  419. /*--------------------------------------------------------------------*/
  420.  
  421. VOID strip_num(line)
  422.  
  423. char line[];
  424. {
  425. int esc=0x011b;
  426.  
  427. /*____________________________________________________________________*/
  428. /*     check for line number at the start of the line-- incase a      */
  429. /* new line was added to the file after the line numbers were added.  */
  430. /*--------------------------------------------------------------------*/
  431.      
  432.      if (atoi(line)==0)
  433.      {
  434.           fputs(line,fp_out);     /* if no line # then output the line*/
  435.           return(EMPTY);          /* without striping non-existent #. */
  436.      }
  437.  
  438.      fputs(&line[8],fp_out);                /*     output line.       */
  439.      Cconout(esc);                          /*   home the cursor.     */
  440.      Cconout('H');
  441.      printf("\n\nStriping line number: %d\n",atoi(line));
  442.  
  443. }
  444.  
  445.  
  446. /*____________________________________________________________________*/
  447. /*               save input line to output file with line             */
  448. /*                   numbers at the start of the line.                */
  449. /*format of line is: 1 space, up to 5 numbers, 2 spaces, and the line.*/ 
  450. /*--------------------------------------------------------------------*/
  451.  
  452. VOID add_num(line,c)
  453.  
  454. char line[];
  455. struct cm *c;
  456. {
  457. int esc=0x011b;
  458.  
  459.      ++c->line_num;
  460.      fprintf(fp_out,"%5d   %s",c->line_num,line);
  461.  
  462.      Cconout(esc);                          /*   home the cursor.     */
  463.      Cconout('H');
  464.      printf("\n\nadding line number: %d\n",c->line_num);
  465.  
  466.  
  467. }
  468.  
  469.  
  470.  
  471. printer(line,c,cmd_line)
  472.  
  473. char line[], *cmd_line[];
  474. struct cm *c;
  475.  
  476. {
  477. static int been_here=0;
  478. static char date[3][3], time[3][3];
  479. int t, t2, line_len, length, status, h_f_flag=0;
  480. char ch, num[9];
  481.  
  482. /* the follow code checks if the printer is ready and gets the time & */
  483. /* date. It is only executed the 1st time this routine is called.     */
  484.  
  485.      if (been_here==0)
  486.      {
  487.       ++been_here;                        /* pass this way never more */
  488.  
  489.      do
  490.        {
  491.           status=Cprnos();       /* is printer ready? status=1 if yes */
  492.  
  493.           if (status==0)
  494.           {
  495.           printf("\n\nPrinter is not ready. Press any key to ");
  496.           printf("continue (Q to quit)\n");
  497.           ch=Cnecin();
  498.           if (ch=='q' || ch=='Q')
  499.            return(QUIT);                   /* all done! exit program. */
  500.           }
  501.        }
  502.      while (status==0);  /* loop until printer is on or 'q' is entered*/
  503.  
  504.      time_date(date,time);                 /* get time & date         */
  505.      }
  506.  
  507. /********************* end of one pass only code. *********************/
  508.  
  509.      h_f_flag=head_foot(c,cmd_line,date,time);
  510.                        /* check if time to print the header or footer */
  511.  
  512. /*____________________________________________________________________*/
  513. /* if the tab flag is on then space the line over tab_amt to that col.*/
  514. /*--------------------------------------------------------------------*/
  515.  
  516.      if (c->tab==ON)
  517.           for (t=0;c->tab_amt != t;++t)
  518.                Cprnout(' ');
  519. /************************ end of tab section **************************/
  520.  
  521. /*____________________________________________________________________*/
  522. /* let the horns sound! we finally print the line. well, almost...    */
  523. /*                    first print the line number.                    */
  524. /*--------------------------------------------------------------------*/
  525.  
  526.      sprintf(num,"%5d  ",++c->line_num);          /* convert to ASCII.*/
  527.      for (t=0;num[t]!='\0';++t)
  528.           Cprnout(num[t]);                      /* print line number. */
  529.  
  530. /*------------- now find out if the line will wrap around.------------*/
  531.  
  532.      line_len=79-(c->tab_amt+8);   /* 79 line size, 8=line # + 2 space*/
  533.       if (strlen(line)>line_len)
  534.      {
  535.           for (t=0;t != line_len && line[t]!='\0';++t)
  536.                Cprnout(line[t]);           /* stop printing after     */
  537.                                            /* reaching end of printer */
  538.                                            /* line.                   */
  539.  
  540. /*____________________________________________________________________*/
  541. /*   call head_foot before printing the 2nd line so if a header or    */
  542. /* is due to be printed, they will be. this way the header and footer */
  543. /*  are kept in their correct place (i.e. not printed 1 line to late).*/
  544. /*--------------------------------------------------------------------*/
  545.  
  546.           if (line[t]!='\0' && c->trun!=ON)  /* if not end-of-line and*/
  547.           {                                  /* truncate isn't 'on'...*/
  548.                h_f_flag=head_foot(c,cmd_line,date,time);
  549.  
  550.             if (h_f_flag!=0)           /* was head or foot performed? */
  551.               Cprnout('\n');               /* if no - CR to 2nd line. */
  552.  
  553.                for (t2=c->tab_amt+9;t2!= 0;--t2)   /* tab for wrap-   */
  554.                  Cprnout(' ');                  /* around 2nd line.   */
  555.                                            /* tab amt + 9 for line #. */ 
  556.                for (;line[t]!='\0';++t)
  557.                  Cprnout(line[t]);       /* print the rest of the line*/
  558.           }
  559.           else Cprnout('\n');              /* truncate the line.      */
  560.      }
  561.      else for (t=0;line[t]!='\0';++t)    /* if no wrap-around then    */
  562.                Cprnout(line[t]);         /* print the whole line.     */
  563.  
  564.  
  565.      return(CONT);
  566. }
  567.  
  568.  
  569.  
  570. /**********************************************************************/
  571. /*                          TIME  and  DATE                           */
  572. /**********************************************************************/
  573. /* this routine load the system time and date and converts it into    */
  574. /* ASCII characters. these characters are returned to the calling     */
  575. /* routine in 2 arrays format so: time[3][3], date[3][3].             */
  576. /* ( "\0" goes in the 3rd cell of the array.)                         */
  577. /*                                                                    */
  578. /* hours will be in: time[0][0], time[0][1]                           */
  579. /* minutes in      : time[1][0], time[1][1]                           */
  580. /* seconds in      : time[2][0], time[2][1]                           */
  581. /*                                                                    */
  582. /* month will be in: date[0][0], date[0][1]                           */
  583. /* day in          : date[1][0], date[1][1]                           */
  584. /* year in         : date[2][0], date[2][1]                           */
  585. /**********************************************************************/
  586.  
  587.  
  588.  
  589. VOID time_date(date,time)
  590.  
  591. char date[][3], time[][3];
  592. {
  593. unsigned int work, date_time;
  594. int t;
  595.  
  596. /* get date */
  597.  
  598.      date_time=Tgetdate();
  599.      work=date_time & 31;          /* mask all but lower 5 bits (day) */
  600.           sprintf(&date[1][0],"%d",work);
  601.      work=(date_time & 480)>>5;    /* mask all but bits 5-8 (month)   */
  602.           sprintf(&date[0][0],"%d",work);
  603.      work=(((date_time & 65024)>>9)+80);
  604.                                    /* mask all but bits 9-15 (year+80)*/
  605.           sprintf(&date[2][0],"%d",work);
  606.  
  607. /* get time */
  608.  
  609.      date_time=Tgettime();
  610.      work=(date_time & 31)*2;        /* mask bits 0=4 (seconds * 2)   */
  611.           sprintf(&time[2][0],"%02d",work);
  612.      work=(date_time & 2016)>>5;     /* mask bits 5-10 (minutes)      */
  613.           sprintf(&time[1][0],"%02d",work);
  614.      work=(date_time & 63488)>>11;   /* mask bits 11-15 (hour)        */
  615.           sprintf(&time[0][0],"%02d",work);
  616.  
  617. }
  618.  
  619.  
  620.  
  621. prt_crt(line,c)
  622.  
  623. char line[];
  624. struct cm *c;
  625. {
  626. int esc=0x011b;
  627. char ch;
  628. static int no_pause;
  629. /*____________________________________________________________________*/
  630. /*     if 23 lines have been printed to the screen then wait for      */
  631. /*                      keypress to continue.                         */
  632. /*--------------------------------------------------------------------*/
  633.  
  634.      if (++c->prt_cnt==23 && no_pause!=ON)
  635.      {
  636.           c->prt_cnt=0;
  637.           printf("Press any key to continue (Q to quit--");
  638.           printf("N to cancel this prompt line).\n");
  639.            ch=Cnecin();
  640.                if (ch=='q' || ch=='Q')   return(QUIT);
  641.            if (ch=='n' || ch=='N') no_pause=ON;
  642.      }
  643.      ++c->line_num;                        /* inc line number counter */
  644.  
  645.      Cconout(esc);                        /* turn on end of line wrap */
  646.      Cconout('v');
  647.  
  648.      if (c->trun==ON && strlen(line) > 74)      /* if truncate is 'on'*/
  649.           printf("%5d %.73s\n",c->line_num,line);
  650.      else
  651.           printf("%5d %s",c->line_num,line);    /* or print it all.   */
  652.  
  653.  
  654.      return(CONT);
  655. }
  656.  
  657.  
  658.  
  659. VOID pause()
  660.  
  661. {
  662. char ch;
  663.  
  664.      Cconws("\n All done. Press any key to exit.");
  665.      ch=Cnecin();
  666.  
  667. }
  668.  
  669.  
  670.  
  671. head_foot(c,cmd_line,date,time)
  672.  
  673. char date[][3],time[][3], *cmd_line[];
  674. struct cm *c;
  675.  
  676. {
  677. static char page[]="page ", head_line[]="          Printed on: ";
  678. int t, name_len, h_f_flag=0;
  679. char ch, num[9], colon_slash;
  680.  
  681.  
  682.      ++c->prt_cnt;       /* keep track of what line the printer is on */
  683.  
  684.  
  685. /*____________________________________________________________________*/
  686. /* if skip over perf flag is on and the printers line cnt=66 - DO IT! */
  687. /*--------------------------------------------------------------------*/
  688.  
  689.      if (c->prt_cnt+c->foot_amt==67 && c->footer==ON)
  690.      {
  691.           for (t=c->foot_amt;t != 0;--t,++c->prt_cnt)
  692.                Cprnout('\n');
  693.           h_f_flag=ON;           /* signal that footer was performed. */
  694.      }
  695.  
  696. /************************ end of footer section ***********************/
  697.  
  698.      if (c->prt_cnt>=66)
  699.           c->prt_cnt=ON;                     /* re-set line counter   */
  700.  
  701.  
  702. /*____________________________________________________________________*/
  703. /* if header flag is on and the printers line cnt=1 then print header */
  704. /*--------------------------------------------------------------------*/
  705.  
  706.      if (c->prt_cnt==1 && c->header==ON)
  707.      {
  708.           h_f_flag=ON;           /* signal that header was performed. */
  709.           Cprnout('\n');                       /* print 2 blank lines */
  710.           Cprnout('\n');
  711.  
  712. /*____________________________________________________________________*/
  713. /* to center the input file's name on the 3rd line 1st get its length */
  714. /* then subtract it from 80 and then divide the remainder by 2. print */
  715. /* this number of spaces to the printer and then the file name.       */
  716. /*                       Voila'! centered print.                      */
  717. /*--------------------------------------------------------------------*/
  718.  
  719.           name_len=strlen(cmd_line[1]);     /* get len of file's name */
  720.           name_len=80-name_len;
  721.      if (name_len>0)                        /* if > 0 then file name  */
  722.           name_len /= 2;                    /* is < 80 char. in length*/
  723.      else                                   /* if < 0 then it's > 80  */
  724.      {                                      /* so don't try to center */
  725.           name_len=0;                       /* it because it'll use 2 */
  726.           c->prt_cnt+=1;                    /* lines anyways. (how you*/
  727.      }                              /* will get 80 or more characters */
  728.                                     /* on the cmd line, I do not know!*/
  729.                                     /* but then you never know, so... */
  730.      for (;name_len != 0;--name_len)
  731.           Cprnout(' ');
  732.      for (t=0;cmd_line[1][t]!='\0';++t)         /* print file name    */
  733.           Cprnout(cmd_line[1][t]);
  734.      Cprnout('\n');
  735.  
  736.  
  737. /*____________________________________________________________________*/
  738. /*       print time, date and page number and then 2 blank lines.     */
  739. /*--------------------------------------------------------------------*/
  740.  
  741.      for (t=0;head_line[t]!='\0';++t)
  742.           Cprnout(head_line[t]);             /* print 'Printed on:'   */
  743.      
  744.      colon_slash='/';
  745.      prt_t_d(date,colon_slash);              /* print date with slash */
  746.      Cprnout(' ');
  747.  
  748.      colon_slash=':';
  749.      prt_t_d(time,colon_slash);              /* print time with colon */
  750.  
  751.      for (t=0;t != 26;++t)                   /* print 26 spaces before*/
  752.           Cprnout(' ');                      /* printing page number. */
  753.  
  754.      for (t=0;page[t]!='\0';++t)
  755.           Cprnout(page[t]);                  /* print 'page'          */
  756.      sprintf(num,"%d",++c->page_no);         /* convert int to ASCII  */
  757.      for (t=0;num[t]!='\0';++t)
  758.           Cprnout(num[t]);                   /* print page number.    */
  759.  
  760.      for (t=0;t!=3;++t)                    /* header takes up 6 lines.*/
  761.           Cprnout('\n');                     /* print 2 blank lines.  */
  762.  
  763.      c->prt_cnt+=6;                          /* update prn line cnt.  */
  764.      }
  765.  
  766.      return(h_f_flag);
  767.  
  768. }
  769.  
  770.  
  771.  
  772. /*____________________________________________________________________*/
  773. /*                prints the time and date to the printer             */
  774. /*     on entry 'colon_slash' equals a '/' when printing the date. it */
  775. /*  separates the mm/dd/yy. 'colon_slash' equals a ':' when printing  */
  776. /*                the date. it separates the hh:mm:ss.                */
  777. /*--------------------------------------------------------------------*/
  778.  
  779. VOID prt_t_d(td,colon_slash)
  780.  
  781. char td[][3],colon_slash;
  782. {
  783. int t, t2;
  784. char ch=' ';
  785.  
  786.      for (t=0;t!=3;++t)
  787.           {                          /* print a space on the 1st pass */
  788.                Cprnout(ch);             /* so we don't get something  */
  789.                ch=colon_slash;          /* like /mm/dd/yy or :hh:mm:ss*/
  790.           for (t2=0;t2!=3;++t2)
  791.                Cprnout(td[t][t2]);
  792.           }
  793.  
  794. }
  795.  
  796.  
  797. VOID skip_lines(c)
  798.  
  799. struct cm *c;
  800.  
  801. {
  802. int esc=0x011b;
  803.  
  804.      ++c->line_num;
  805.  
  806.      Cconout(esc);                          /*   home the cursor.     */
  807.      Cconout('H');
  808.      printf("\n\nreading line number: %d",c->line_num);
  809.      printf("  but waiting for line: %d\n",c->start_ln);
  810.  
  811.  
  812. }
  813.